﻿#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Diagnostics;
using System.IO;
using log4net;
using log4net.Config;

namespace Grawlix.Client
{
	/// <summary>
	/// The main entry point of the program.
	/// </summary>
	public static class MainEntry
	{
		/// <summary>
		/// The log used to sent output information.
		/// </summary>
		private static readonly ILog _log =
			LogManager.GetLogger(typeof(MainEntry));

		/// <summary>
		/// The main entry point of the program.
		/// </summary>
		/// <returns>0 on success, else an error code.</returns>
		private static int Main()
		{
			Debug.Listeners.Add(new ConsoleTraceListener());
			Debug.AutoFlush = true;
			XmlConfigurator.ConfigureAndWatch(
				new FileInfo("Properties/Grawlix.log4net"));
			if (_log.IsInfoEnabled)
			{
				_log.Info(DateTime.Now +
				          "Client started successfully in " +
				          AppDomain.CurrentDomain);
			}
			using (var client = new ClientWindow())
				client.Run();
			if (_log.IsInfoEnabled)
			{
				_log.Info("Client exited gracefully at " + DateTime.Now +
				          ".");
			}
			return 0;
		}
	}
}